import { ref, reactive, onMounted } from 'vue'
import axios from 'axios' //发送http请求

export default function () { //hooks封装数据和方法
    let dogList = reactive([ //数据
        ''
    ])
    async function getDog() { //方法
        try {
            let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
            dogList.push(result.data.message)
        } catch (error) { //async-await用try-catch捕获错误
            alert(error)
        }
    }
    onMounted(() => { //钩子函数
        getDog()
    })
    return { dogList, getDog } //返回
}